﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.SessionState;
using System.IO;
using System.Web;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //var results = HHMMS.FileServer.AttachmentInfoProvider.Instance.SelectAll();
            //HHMMS.Core.Service.ProductService service = new HHMMS.Core.Service.ProductService();
            //var products = service.GetProducts();
            
            //string path = @"/Products.ascx";
            //var viewManager = new ViewManager<HHMMS.UI.Modules.FileTemplate.Products>();
            //var control = viewManager.LoadViewControl(path);
            //string t = viewManager.RenderView(control);

            //var configs = ResourceConfigManager.ResourceConfigs;

            

            //ZipCompress zip = new ZipCompress();
            //zip.Compress(@"D:\我的项目\20121012_导购系统\Code\Test\bin\Debug\ResourceFiles\All", @"C:\All.zip", true);

            //try
            //{
            //    var a = 0;
            //    var i = 100 / a;
            //}
            //catch (Exception ex)
            //{
            //    Bingosoft.Common.Logging.LogManager.GetCurrentClassLogger().Error("asddas", ex);
            //}



            Console.WriteLine("ok");
            Console.Read();
        }
    }

    public class ViewManager<T> where T : UserControl
    {
        private Page m_pageHolder;

        public T LoadViewControl(string path)
        {
            this.m_pageHolder = new Page();
            this.m_pageHolder.AppRelativeTemplateSourceDirectory = Environment.CurrentDirectory;
            this.m_pageHolder.AppRelativeVirtualPath = path;
            return (T)this.m_pageHolder.LoadControl(path);
        }

        //public T LoadViewControl(string virtualPath)
        //{
        //    this.m_pageHolder = new Page();
        //    return (T)this.m_pageHolder.LoadControl(typeof(T), null);
        //}

        public string RenderView(T control)
        {
            StringWriter output = new StringWriter();

            //this.m_pageHolder.Controls.Add(control);
            //HttpContext.Current.Server.Execute(this.m_pageHolder, output, false);

            HtmlTextWriter result = new HtmlTextWriter(output);
            
            control.RenderControl(result);

            return output.ToString();
        }
    }
}
